// 定义核心数据结构类型
export interface IndexMeta {
  id?: string;
  index_name: string;
  hash: string;
  created_at: number;
  updated_at: number;
}

export interface IndexAlias {
  id?: string;
  meta_id: string;
  alias_name: string;
  created_at: number;
  updated_at: number;
}

export interface IndexField {
  id?: string;
  meta_id: string;
  field_path: string;
  field_type: string;
  is_aggregatable: boolean;
  is_searchable: boolean;
  analyzer: string;
  created_at: number;
  updated_at: number;
}

export interface IndexSetting {
  id?: string;
  meta_id: string;
  setting_key: string;
  setting_value: string;
  created_at: number;
  updated_at: number;
}

export interface IndexShard {
  id?: string;
  meta_id: string;
  shard_id: string;
  shard_type: string; // "primary" or "replica"
  node_name: string;
  state: string;
  created_at: number;
  updated_at: number;
}

// 从接口获取的原始数据结构
export interface RawIndexData {
  id?: string;
  index_name: string;
  aliases: string[]; // 别名列表
  fields: Array<{
    field_path: string;
    field_type: string;
    is_aggregatable: boolean;
    is_searchable: boolean;
    analyzer?: string;
  }>;
  settings: Record<string, string>; // 键值对
  shards: Array<{
    shard_id: string;
    shard_type: string;
    node_name: string;
    state: string;
  }>;
  hash: string; // 当前状态的哈希
}

// 返回的数据结构
export interface UpdateResult {
  indexMeta: {
    toUpdate: IndexMeta[];
    toInsert: IndexMeta[];
  };
  aliases: {
    toDelete: string[]; // alias表的id列表
    toInsert: IndexAlias[];
  };
  fields: {
    toDelete: string[]; // field表的id列表
    toInsert: IndexField[];
  };
  settings: {
    toDelete: string[]; // setting表的id列表
    toInsert: IndexSetting[];
  };
  shards: {
    toDelete: string[]; // shard表的id列表
    toInsert: IndexShard[];
  };
  hasChanges: boolean;
}
